import PcaCode from './pca-code.json'
import PcasCode from './pcas-code.json'
import PcasCodeFlat from './pcas-code-flat.json'
import deepFreeze from '@utils/deepFreeze'

// Map, 提高查找效率 ( Java code: Map<String, String> map = new HashMap() )
const pcasCodeFlatMap = new Map(PcasCodeFlat.map(im => [im.value, im.label])) // 44703 条数据
// 省市镇区数据
export const provinceCityCountyData = deepFreeze(PcaCode)
// 省市镇区数据
export const provinceCityCountyTownData = deepFreeze(PcasCode)
// 将编码转成汉字
export const codeToText = (codeStringOrStringArray = '') => {
  if (Object.prototype.toString.call(codeStringOrStringArray) === '[object String]') {
    return pcasCodeFlatMap.get(codeStringOrStringArray) || codeStringOrStringArray
  }
  if (Object.prototype.toString.call(codeStringOrStringArray) === '[object Array]') {
    return codeStringOrStringArray.map(im => codeToText(im))
  }
  // 返回自己, 没有实际意义
  return codeStringOrStringArray
}
